<?php
namespace Admin\Controller;
use Think\Controller;
class CommentController extends CommonController {
     public function lists(){
		$Comment = M("Comment");
		$list = $Comment->query("select * from Comment");
		$this->assign("lists",$list);
		if($_REQUEST["title"]){
			$title = $_POST["title"];
			$Comment = M('Comment'); // 实例化User对象
			$numPerPage = empty($_REQUEST["numPerPage"])?2:$_REQUEST["numPerPage"];
			$count  = $Comment->where("title = '$title'")->count();// 查询满足要求的总记录数
			$Page  = new \Think\Page($count,$numPerPage);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show  = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list = $Comment->where("title = '$title'")->order("id desc")->limit($Page->firstRow.','.$Page->listRows)->select();
			//当前数据
			$this->assign("lists",$list);
			//总条数
			$this->assign("totalCount",$count);
			//每页显示多少条
			$this->assign("numPerPage",$numPerPage);
			//页标数字多少个
			$this->assign("pageNumShown",$Page->totalPages);
			//当前显示第几页
			$page = empty($_REQUEST["pageNum"])?1:$_REQUEST["pageNum"];
			$this->assign("currentPage",$page);
			$this->assign("title",$title);
		}else{
			$Comment = M('Comment'); // 实例化User对象
			$numPerPage = empty($_REQUEST["numPerPage"])?2:$_REQUEST["numPerPage"];
			$count  = $Comment->count();// 查询满足要求的总记录数
			$Page  = new \Think\Page($count,$numPerPage);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show  = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list = $Comment->order("id desc")->limit($Page->firstRow.','.$Page->listRows)->select();
			//当前数据
			$this->assign("lists",$list);
			//总条数
			$this->assign("totalCount",$count);
			//每页显示多少条
			$this->assign("numPerPage",$numPerPage);
			//页标数字多少个
			$this->assign("pageNumShown",$Page->totalPages);
			//当前显示第几页
			$page = empty($_REQUEST["pageNum"])?1:$_REQUEST["pageNum"];
			$this->assign("currentPage",$page);
		}
		$this->display();
	}
	public function del(){
		//取得要删除的id
		
		$id = $_GET["uid"];
		$sql = M("comment")->where("id=$id")->delete($_POST);
		if($sql){
			$this->success("删除成功");
		}
	}
}